/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package proxy;

import javax.servlet.ServletContext;
import org.apache.http.impl.client.DefaultHttpClient;

/**
 *
 * @author Hue
 */
public class ChangeVPN implements Runnable {
    private VPN vpn;
    private String clientIp;
    
    public ChangeVPN(ServletContext context, String clientIp) {
        this.vpn = (VPN) context.getAttribute(InitServlet.PROXY_VPN);
        this.clientIp = clientIp;
        clearCookie(context, clientIp);
    }

    @Override
    public void run() {
        vpn.viewDone(clientIp);
        if(vpn.isAllFinished()) {
            vpn.process();
        }
    }
    
    private void clearCookie(ServletContext context, String clientIp) {
        String DEFAULT_HTTP_CLIENT = "DEFAULT_HTTP_CLIENT_" + clientIp;
        DefaultHttpClient httpclient = (DefaultHttpClient) context.getAttribute(DEFAULT_HTTP_CLIENT);
        httpclient.getCookieStore().clear();
    }
}
